Ext.ux.ProgressManager=function(){
	var taskRunner,progressBars,window;
	
	progressBars=new Array();
	taskRunner=new Ext.util.TaskRunner();
	
	return {
		/**
		 * @param	progressBar
		 * 添加进度条
		 * @type	Ext.ux.ProgressBar
		 * @return	this
		 */
		addProgressBar:function(progressBar){
			if(progressBar.taskRunner==undefined){
				progressBar.setTaskRunner(taskRunner);
			}
			
			progressBars[progressBars.length]=progressBar;
			return this;
		},
		getWindow:function(){
			
			if(!window){
				this.newWindow();
                            
			}
						
			return window;
		},
		newWindow:function(){			
			window=new Ext.Window({
                title : '文件上传情况：',
				width : 300,
				minWidth : 300,
				minHeight : 200,
				modal: true,
				closable:false,
				layout : 'anchor',
				plain : true,
				bodyStyle : 'padding:5px;',
				buttonAlign : 'center',
				buttons:[{
					cls:'confirm',
					text:'确定',
					handler:this.hide.createDelegate(this),
					disabled:true }]
            });
            	
            Ext.each(progressBars,function(progressBar,i,progressBars){
                window.add({
                	layout:'form',
					frame:true,
					items:[{
						xtype:'label',
						text :progressBar.labelText
						},progressBar.progressBar]
                });
            });
            
            window.add({
            	
            });
            
		}
		,
		hide:function(){
			this.getWindow().hide();
		}
		,
		show:function(){
			this.resetLabelText();
			this.getWindow().show();
		},
		//启动
		start:function(){
			if(!this.getWindow().isVisible()){
				this.show();
			}
			
			this.each(function(progressBar){
				progressBar.reset();
				progressBar.start();
			});
		},
		stop:function(){
			this.each(function(progressBar){
				progressBar.resetProgress();
				progressBar.complete();
				progressBar.stop();
			});
			this.getWindow().buttons[0].enable();
		}
		,
		reset:function(){
			this.each(function(progressBar){
				progressBar.progressBar.reset();
			});
		},
		resetLabelText:function(){
			this.each(function(progressBar,i){
				progressBar.resetLabelText();		
			});
			var items=window.items.items;
			for(var i=0,len=items.length;i<len;i++){				
				items[i].items.items[0].text=progressBars[i].labelText;
				if(items[i].items.items[0].getEl()){
					Ext.DomHelper.overwrite(items[i].items.items[0].getEl().dom,progressBars[i].labelText)
				}
			}	
			window.doLayout();
		}
		,
		each:function(fn,scope){
			for(var i=0,len=progressBars.length;i<len;i++){
				/**
				 * scope||objs[i]		表示此函数的上下文为scop，如果scope为空则为objs[i]
				 * objs[i]				为传入fn的参数
				 * this					表示把调用此each方法的对象做为输入参数
				 * i					为在数组中的位置
				 * 如果此函数有回返值为false则，跳出循环
				 */
				if(fn.call(scope || progressBars[i], progressBars[i], i, this) === false) {
	                break;
	            }
			}
		}
	}
}();

